let Fly = require('../lib/fly.js')
let fly = new Fly
fly.config.timeout = 60000
fly.interceptors.request.use((request) => {
  let app = getApp()
  //给所有请求添加自定义header
  request.headers["content-type"] = 'application/json'
  request.headers["token"] = app.globalData.Authorization
  return request
})

//添加响应拦截器，响应拦截器会在then/catch处理之前执行
fly.interceptors.response.use((res) => {
    let app = getApp()
  // app.globalData.Authorization = res.data.accessToken
  // 只将请求结果的data字段返回
    return res.data
  },
  (err) => {
    //发生网络错误后会走到这里
    //取下下拉刷新
    wx.stopPullDownRefresh()
    wx.hideNavigationBarLoading()
    // wx.showToast({ title: '请求超时', icon: 'none'})
    // return Promise.resolve(err, 'xxxx')
  }
)
export default fly